package com.motong.gongdan.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 联络灯分级通知表
 */
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "联络灯分级通知表")
@Data
@Accessors(chain = true)
@TableName(value = "lamp_type_notice")
public class LampTypeNotice extends PublicPo implements Serializable {
    /**
     * id分级
     */
    @TableId(value = "id", type = IdType.AUTO)
    @ApiModelProperty(value = "id分级")
    private Long id;

    /**
     * 联络灯类型id(lamp_type表id)
     */
    @TableField(value = "lamp_type_id")
    @ApiModelProperty(value = "联络灯类型id(lamp_type表id)")
    private Long lampTypeId;

    /**
     * 延时时长(分钟)
     */
    @TableField(value = "delay_time")
    @ApiModelProperty(value = "延时时长(分钟)")
    private Integer delayTime = 0;

    /**
     * 通知方式(0 微信, 1 ai语音)
     */
    @TableField(value = "info_type")
    @ApiModelProperty(value = "通知方式(0 微信, 1 ai语音,多个以,号隔开)")
    private String infoType = "0";

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    @ApiModelProperty(value = "创建时间", hidden = true)
    private Date createTime;

    /**
     * 创建人
     */
    @TableField(value = "create_user")
    @ApiModelProperty(value = "创建人", hidden = true)
    private Integer createUser;

    /**
     * 通知方式
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "通知方式名称")
    private String infoTypeName;


    /**
     * 发送人员名称
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "发送人员名称(数据回显)")
    private String userNames;

    /**
     * 发送人员(数组)
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "发送人员(数组)")
    private List<Integer> userIdList;

    /**
     * 发送人员
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "发送人员逗号隔开字符串")
    private String userIds;

    /**
     * 轮次
     */
    @TableField(value = "round_num")
    @ApiModelProperty(value = "轮次")
    private Integer roundNum;

    /**
     * 轮次间隔时间
     */
    @TableField(value = "interval_time")
    @ApiModelProperty(value = "轮次间间隔时间")
    private Integer intervalTime;



    public LampTypeNotice setInfoType(String infoType) {
        if (StringUtils.hasLength(infoType)) {
            Arrays.asList(infoType.split(",")).forEach(i -> {
                String typeName = "0".equals(i) ? "微信" : "语音";
                this.infoTypeName = !StringUtils.hasLength(this.infoTypeName) ? typeName : this.infoTypeName.concat(",").concat(typeName);
            });
            this.infoTypeName = (infoType.contains("0") ? "微信" : "语音");
        }
        this.infoType = infoType;
        return this;
    }

    private static final long serialVersionUID = 1L;
}